// pages/duobao/partiUsers/partiUsers.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
import * as utils from '../../../utils/util.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iconList: [],
    joinNum: 0,
    page: 1,
    id: 0,
    pageSize: 100,
    hasMoreData: true,
    isShow: true //是否显示‘加载更多’
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let id = options.id;
    this.setData({
      id: id
    })
    console.log("page==" + this.data.page)
    this.getAllUser();
  },
  getAllUser: function() {
    S_request.duobao.getJoinDBList(this.data.page, this.data.id, (result) => {
      let iconList = this.data.iconList;
      if (result.page == 1) {
        iconList = []
      } else {
        // 隐藏加载框
        wx.hideLoading();
      }
      if (result.lists.length < this.data.pageSize) {
        iconList = iconList.concat(result.lists);
        this.setData({
          hasMoreData: false,
          isShow: false
        })
      } else {
        iconList = iconList.concat(result.lists);
        this.setData({
          hasMoreData: true,
          page: this.data.page + 1,
          isShow: true
        })
      }
      this.setData({
        iconList: iconList,
        joinNum: result.count
      })
    })
  },
  loadMore: function() {
    console.log("hasMoreData==" + this.data.hasMoreData)
    if (this.data.hasMoreData) {
      wx.showLoading({
        title: '玩命加载中',
        mask: true
      })
      this.getAllUser();
    } else {
      if (this.data.page != 1) {
        wx.showToast({
          title: '没有更多数据',
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    wx.showShareMenu({
      withShareTicket: true,
      success: function() {}
    });
    let obj = {'pagepath': CONFIG.SHARE.pathDuobao}
    S_request.index.recordShare("-6", obj);
    return {
      title: CONFIG.SHARE.titleDuobao,
      path: CONFIG.SHARE.pathDuobao,
      imageUrl: CONFIG.SHARE.imagDuobao,
      success: res => { //新版不走回调
        console.log("分享成功")
      }
    }
  },
})